package cn.bdqn.controller;

import cn.bdqn.dao.ProductDaok;
import cn.bdqn.pojo.Product;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author: 苏闻君
 * @Date: Created in 2020/7/14  16:57
 * 商品
 */
@Controller
public class ProductControllerk {
    @Resource
    ProductDaok productDaok;

    /**
     * 查询全部商品
     * @param model
     * @param pageNum
     * @return
     */
   @RequestMapping("/shop")
    public String selectShop(Model model,@RequestParam(defaultValue = "1") int pageNum){
       PageHelper.startPage( pageNum, 6);
        List<Product> list=productDaok.selectAll();

       PageInfo<Product> pageInfo = new PageInfo<Product>(list);

       model.addAttribute("pageInfo",pageInfo);
        return "shop";
    }
    @RequestMapping("/shopSelect")
    public String selectShops(Model model, HttpServletRequest request,@RequestParam(defaultValue = "1") int pageNum){
       String name=request.getParameter("text");
        PageHelper.startPage( pageNum, 6);
        List<Product> list1=productDaok.selectShop(name);
        PageInfo<Product> pageInfo = new PageInfo<Product>(list1);

        model.addAttribute("pageInfo",pageInfo);
        return "shop";
    }

    @RequestMapping("/shopDetails")
    public String selectDuct(Model model,HttpServletRequest request){
       Integer id=Integer.parseInt(request.getParameter("id"));
       Product product=new Product();
       product = productDaok.selectDuct(id);
       model.addAttribute("product",product);
       return "shopDetails";
    }
}
